﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebRamosUC.Models
{
    public class ConcreteAyudanteIterator: AyudanteIterator
    {
        private static ConcreteAyudanteIterator _instance;
        private  List<Ayudante> _aggregate;
        private int _current = 0;
 
        // Constructor
        public static ConcreteAyudanteIterator Instance(IEnumerable<Ayudante> aggregate)
        {
            if (_instance == null)
            {
                _instance = new ConcreteAyudanteIterator();
                _instance._aggregate = aggregate.ToList();
            }
            return _instance;
        }

        public static void UpdateReference()
        {
            if (_instance != null)
            {
               // _instance._aggregate = aggregate.ToList();
                _instance._current = 0;
            }

        }

        protected ConcreteAyudanteIterator() 
        {
        }
 
        // Gets first iteration item
        public override object First()
        {
            return _aggregate[0];
        }
 
        // Gets next iteration item
        public override object Next()
        {
            object ret = null;
            if (_current < _aggregate.Count - 1)
            {
                ret = _aggregate[++_current];
            }
 
            return ret;
        }
 
        // Gets current iteration item
        public override object CurrentItem()
        {
            return _aggregate[_current];
        }
 
        // Gets whether iterations are complete
        public override bool IsDone()
        {
            return _current >= _aggregate.Count ;
        }
        public void NextCounter() 
        {
            _current++;
        }
    }
}